package myta.bean;

import javax.faces.component.html.HtmlDataTable;

import myta.base.FormBase;
import myta.model.DataRow;
import myta.model.DataTable;
import myta.service.Command;
import myta.service.SQLexec;

public class Nilai extends FormBase{
	private DataTable datatable;
	private HtmlDataTable htmldatatable;
	
	@Override
	public void init() throws Exception {
		formName = "nilai";
		
		htmldatatable = new HtmlDataTable();
		datatable = new DataTable();
	}

	@Override
	public void hapus() throws Exception {
		int r = htmldatatable.getRowIndex();
		DataRow dr = datatable.getRow(r);
		
		String sql = "delete from nilai where idnilai = ?";
		Command command = SQLexec.makeCommand(sql);
		command.setObject(1, dr.getString("idnilai"));
		command.executeUpdate();
	}

	@Override
	public void tampil() throws Exception {
		String sql = "select n.idnilai, s.thnajaran, k.namakelas, m.namamapel, g.nama, jn.jenisnilai from nilai n ";
		sql += "inner join kelassiswa ks on n.idkelassiswa = ks.idkelassiswa ";
		sql += "inner join kelas k on ks.idkelas = k.idkelas ";
		sql += "inner join semester s on k.idsemester = s.idsemester ";
		sql += "inner join mapel m on n.idmapel = m.idmapel ";
		sql += "inner join jenisnilai jn on n.idjenisnilai = jn.idjenisnilai ";
		sql += "inner join jadwal j on j.idkelassiswa = n.idkelassiswa and j.idmapel = m.idmapel ";
		sql += "inner join guru g on j.idguru = g.idguru ";
		Command command = SQLexec.makeCommand(sql);
		datatable = command.executeQuery();
	}

	public DataTable getDatatable() {
		return datatable;
	}

	public void setDatatable(DataTable datatable) {
		this.datatable = datatable;
	}

	public HtmlDataTable getHtmldatatable() {
		return htmldatatable;
	}

	public void setHtmldatatable(HtmlDataTable htmldatatable) {
		this.htmldatatable = htmldatatable;
	}
	
}
